package ma.ac.onousc.gestionfi.budget.model.DAO.DAOBean;

import java.util.List;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import ma.ac.onousc.gestionfi.budget.model.Personnel;
import ma.ac.onousc.gestionfi.budget.model.DAO.PersonnelDAO;

@Stateless
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class PersonnelDAOBean extends GenericEJB3Bean<Personnel, Integer>
		implements PersonnelDAO {
	@SuppressWarnings("unchecked")
	@Override
	public Personnel authentifier(String login, String pwd) {
		List<Personnel> liste = getEntityManager()
				.createNamedQuery("Personnel.authentifier")
				.setParameter("LOGIN", login).setParameter("PWD", pwd)
				.getResultList();
		if (liste != null && liste.size() > 0) {
			return liste.get(0);
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Personnel> findAllPersonnel() {
		return getEntityManager().createNamedQuery("Personnel.findAll")
				.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Personnel> findByEtab(int id) {

		return getEntityManager().createNamedQuery("Personnel.findByEtb")
				.setParameter("ID", id).getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public Personnel findByLogin(String login) {
		List<Personnel> lst =  getEntityManager().createNamedQuery("Personnel.findByLogin")
				.setParameter("LOGIN", login).getResultList();
		if(lst.size()>0)return lst.get(0);
		else return null;
	}
}